/**
 *  Queue - LinkedList Implementation
 *  
 */

class QueueLinkedList<T> {

    private Node first, last;
    private int total;

    private class Node {
        private T t;
        private Node next;
    }

    public void enqueue(T t) {
        Node current = last;
        last = new Node();
        last.t = t;
        if (current == null) {
            first = last;
        } else {
            current.next = last;
        }

        total++;
    }

    public T dequeue() {
        if (first == null) {
            return null;
        }

        T t = first.t;
        
        first = first.next;
        total--;

        if (total == 0) {
            last = null;
        }

        return t;
    }

    public T peek() {
        if (first == null) {
            return null;
        }

        return first.t;
    }

    public int size() {
        return total;
    }

    public Boolean isEmpty() {
        return total == 0;
    }

}

